<?php

namespace App\Transformers\Role;

use App\Models\Role;
use App\Transformers\Permission\PermissionTransformer;
use League\Fractal\TransformerAbstract;

class RoleTransformer extends TransformerAbstract
{
    protected  $availableIncludes = ['permissions'];

    public function transform(Role $data)
    {
        return [
            'id' => $data->id,
            'name' => $data->name ?? '',
            'cn_name' => $data->cn_name ?? '',
            'guard_name' => $data->guard_name ?? '',
            'status' => $data->Frontstatus[$data->status] ?? '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    public function includepermissions(Role $role){
        return $this->collection($role->permissions,new PermissionTransformer());
    }
}
